import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_tutorial/app/modules/home/news_controller.dart';

class NewsPage extends GetView<NewsController> {

  @override
  Widget build(BuildContext context) {
    controller.uniquekey.value = Get.parameters['uniquekey']!;
    print(Get.parameters);
    print(Get.arguments);
    print(controller.uniquekey);

    return Scaffold(
      appBar: AppBar(
        title: Text('NewsPage')
      ),

      body: Container(
        margin: EdgeInsets.all(10),
        child: ListView(
          children: [
            Expanded(
              child: controller.obx(
                (state) => Column(
                  children: [
                    Text(
                      state!.title!,
                      style: Theme.of(context).textTheme.headline5
                    ),
                    Divider(),
                    Image.network(
                      state.thumbnailPicS!,
                      width: Get.width,
                    ),
                  ],
                ),
                onLoading: Center(child: CircularProgressIndicator()),
                onError: (error) => Center(
                  child: Text(
                    'Error: $error',
                    style: TextStyle(fontSize: 18),
                    textAlign: TextAlign.center,
                  ),
                ),
              ),
            ),
            ElevatedButton(
              onPressed: () {
                Get.back(result: {"success": true});
              }, 
              child: Text('回退带参数')
            )
          ],
        )
      )
    );
  }
}